package com.example.androidpattern.state.classes;

import android.util.Log;

import com.example.androidpattern.state.interfaces.IState;

/**
 * @ClassName: SoldState$
 * @Description: java类作用描述
 * @Author: xinya
 * @CreateDate: 2020/11/11$ 17:39$
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class SoldState implements IState {
    private static final String TAG = "SoldState";
    private VendingMachine mMachine;

    public SoldState(VendingMachine machine) {
        mMachine = machine;
    }

    @Override
    public void insertMoney() {
        Log.e(TAG, "insertMoney: 已经投币,无需再次投入");
    }

    @Override
    public void outMoney() {
        Log.e(TAG, "outMoney: 正在出货, 禁止退钱");
    }

    @Override
    public void chooseGoods() {
        Log.e(TAG, "chooseGoods: 正在出货,禁止选择商品");
    }

    @Override
    public void outGoods() {
        int count = mMachine.getGoodsCount();
        if (count > 0)  {
            mMachine.setState(mMachine.getNoMoneyState());
            mMachine.setGoodsCount(--count);
            Log.d(TAG, "outGoods: 出货成功");
        } else {
            mMachine.setState(mMachine.getSoldOutState());
            Log.d(TAG, "outGoods: 商品售罄,出货失败！");
        }
    }
}
